#include <bits/stdc++.h>

using namespace std;



struct ListNode {
    int val;
    ListNode *next;
    ListNode(int x) : val(x), next(NULL) {}
};

class Solution1 {
public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
        ListNode *p=l1,*q=l2,*r=nullptr,*head=nullptr;
        if(l1==nullptr) return l2;
        if(l2==nullptr) return l1;
        while(p&&q){
            if(p->val<=q->val){
                if(r){
                    r->next=p;
                }
                if(r==nullptr) head=p;
                r=p;
                p=p->next;
            }else{
                 if(r){
                    r->next=q;
                }
                if(r==nullptr) head=q;
                r=q;            
                q=q->next;
            }
        }
        while(p){
            r=p;
            p=p->next;
        }
        while(q){
            r->next=q;
            r=q;
            q=q->next;
        }
        return head;
    }
};

class Solution {
public:
    ListNode* mergeTwoLists(ListNode* l1, ListNode* l2) {
        ListNode *r=nullptr,*head=new ListNode(1);
        r=head;
        while(l1&&l2){
            if(l1->val<=l2->val){
                head->next=l1;
                l1=l1->next;
            }else{
                head->next=l2;
                l2=l2->next;
            }
            head=head->next;
        }
        if(l1){
            head->next=l1;
        }else{
            head->next=l2;
        }
        return r->next;
    }
};

int main(){




    return 0;
}